//
//  BKSignVoucherCollectionViewCell.m
//  bestkeep
//
//  Created by yons on 16/12/5.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKSignVoucherCollectionViewCell.h"
#import "BKMainCommon.h"

#import "BK_OD_Color.h"
@implementation BKSignVoucherCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        [self initView];
    }
    return self;
}

-(void)initView{
    
    self.backgroundColor=[UIColor clearColor];
    
    /*
     * 打底的背景
     */
    _view_back =[[UIView alloc]init];
    _view_back.backgroundColor= [UIColor clearColor];
    [self addSubview:_view_back];
    [_view_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(10);
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.bottom.mas_equalTo(self.mas_bottom).offset(0);
    }];
    
    
    /*
     * 白色图片
     */
    _whiteBV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BKIntegral_youhuiquan"]];
    [_view_back addSubview:_whiteBV];
    [_whiteBV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_back.mas_top).offset(0);
        make.left.mas_equalTo(_view_back.mas_left).offset(0);
        make.right.mas_equalTo(_view_back.mas_right).offset(0);
        make.height.mas_equalTo(154/2.0);
    }];
    
    
    _lab_price = [UILabel new];
    _lab_price.font=[UIFont systemFontOfSize:15.0];
    [_view_back addSubview:_lab_price];
    _lab_price.text= @"加载中...";
    _lab_price.textColor=kOrderBlack1;
    _lab_price.textAlignment=NSTextAlignmentCenter;
    
    
    _lab_sub = [UILabel new];
    _lab_sub.text = @"加载中...";
    _lab_sub.textColor=kOrderLightGrey1;
    _lab_sub.font=[UIFont systemFontOfSize:12.0];
    [_view_back addSubview:_lab_sub];
    
    [_lab_price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_view_back.mas_left).offset(32/2.0);
        make.top.equalTo(_view_back.mas_top).offset(25/2.0);
    }];
    
    [_lab_sub mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_lab_price.mas_right).offset(10);
        make.right.equalTo(_whiteBV.mas_right).offset(-10);
        make.bottom.equalTo(_lab_price.mas_bottom).offset(0);
    }];
    
    
    
    /*
     * 3000积分
     */
    _lab_Number = [UILabel new];
    _lab_Number.text = @"加载中...";
    _lab_Number.textColor=RGB(255, 255, 255);
    _lab_Number.font=[UIFont systemFontOfSize:14];
    _lab_Number.textAlignment=NSTextAlignmentCenter;
    _lab_Number.backgroundColor=kOrderBKGreen;
    [_view_back addSubview:_lab_Number];
    [_lab_Number mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_view_back.mas_left).offset(0);
        make.right.equalTo(_view_back.mas_right).offset(0);
        make.bottom.equalTo(_view_back.mas_bottom).offset(0);
        make.top.equalTo(_whiteBV.mas_bottom).offset(0);
        
    }];
    
    
    _lab_type= [UILabel new];
    _lab_type.text = @"加载中...";
    _lab_type.textColor=kOrderLightGrey1;
    _lab_type.font=[UIFont systemFontOfSize:12.0];
    _lab_type.textAlignment=NSTextAlignmentLeft;
    [_view_back addSubview:_lab_type];
    [_lab_type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_view_back.mas_left).offset(32/2.0);
        make.right.equalTo(_view_back.mas_right).offset(-10);
        make.bottom.equalTo(_lab_Number.mas_top).offset(-13);
    }];
    
}
-(void)relayOutUI:(id)data{
    
    //    "coupon_amount": "￥20.00",
    //     "coupon_amount_text": "立减20.00",
    //     "effective_days": "7//有效期",
    //     "exchange_integral": "50//兑换所需积分",
    //     "userRange": "全场商品",
    //     "couponId": "xxxx//购物券id",
    
    if (data) {
        BKSignVoucherModel *model = [[BKSignVoucherModel alloc]init];
        if ([data isKindOfClass:[BKSignVoucherModel class]]) {
            model=data;
        }else{
            [model setValuesForKeysWithDictionary:data];
        }
        
        NSString * money=[NSString stringWithFormat:@"¥%@",model.coupon_amount];
        _lab_sub.text = [NSString stringWithFormat:@"%@",model.coupon_amount_text];
        _lab_type.text = [NSString stringWithFormat:@"%@",model.userRange];
        _lab_Number.text =[NSString stringWithFormat:@"%@",model.exchange_integral];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:money];
//        // 修改富文本中的不同文字的样式
//        [attri addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12.0] range:NSMakeRange(0, 1)];
//        // 设置数字为红色
//        [attri addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:18.0] range:NSMakeRange(1, money.length-1)];
        // 修改富文本中的不同文字的样式
        [attri addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15.0] range:NSMakeRange(0, 1)];
        // 设置数字为红色
        [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:28.0] range:NSMakeRange(1, money.length-1)];
        
        
        
        _lab_price.attributedText=attri;
        
        [_lab_price mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_view_back.mas_left).offset(32/2.0);
            make.top.equalTo(_view_back.mas_top).offset(25/2.0);
            make.width.mas_equalTo([BKIntegralCommon getWidthWithTitle:[money substringWithRange:NSMakeRange(0, 1)] font:15.0]+[BKIntegralCommon getWidthWithTitle:[money substringWithRange:NSMakeRange(1, money.length-1)] font:28.0]+15);
        }];
        
        [_lab_sub mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_lab_price.mas_right).offset(0);
            make.right.equalTo(_whiteBV.mas_right).offset(-10);
            make.bottom.equalTo(_lab_price.mas_bottom).offset(-2);
        }];
        
    }
}


+(CGSize)setSize:(id)data{
    if (!data) {
        return CGSizeZero;
    }else{
        return CGSizeMake((ScreenWidth-20.0f)/2.0-5.0f,110+10);
    }
}
@end
